package dao

import (
	"context"
	"github.com/ecodeclub/ekit/slice"
	"github.com/olivere/elastic/v7"
)

type LikeElasticDAO struct {
	client *elastic.Client
}

func NewLikeElasticDAO(client *elastic.Client) *LikeElasticDAO {
	return &LikeElasticDAO{client: client}
}
func (h *LikeElasticDAO) Search(ctx context.Context, uid int64, biz string) ([]int64, error) {
	query := elastic.NewBoolQuery().Must(
		elastic.NewTermQuery("uid", uid),
		elastic.NewTermQuery("biz", biz),
	)
	res, err := NewSearcher[BizTag](h.client, LikeIndexName).Query(query).Do(ctx)
	if err != nil {
		return nil, err
	}
	ids := slice.Map(res, func(idx int, src BizTag) int64 {
		return src.BizId
	})
	return ids, nil
}
